package medOffice;

import java.util.Calendar;
import java.util.GregorianCalendar;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

/**
 * Testes da classe Representante.
 * @author F.Demontie 
 *
 */
public class RepresentanteTest {
	private Representante rep1, rep2;
    private Calendar dataPassada, hoje, dataFutura;
    
	@Before
	public void construtores() throws Exception {
		rep1 = new Representante("Antao", "lafep");
        rep2 = new Representante("J", "unisam");
        
        dataPassada = new GregorianCalendar(2009, 9, 10);
        hoje = new GregorianCalendar();
        dataFutura = new GregorianCalendar(2009, 11, 15);
	}
	
	@Test(expected = Exception.class)
	public void RepresentanteNomeNull() throws Exception {
		new Representante(null, "simlab");
	}
	
	@Test(expected = Exception.class)
	public void RepresentanteLabNull() throws Exception {
		new Representante("Jenesio", null);
	}
		
	@Test(expected = Exception.class)
	public void RepresentanteConsrutorNull() throws Exception {
		new Representante(null, null);
	}
	
	 @Test
     public void RepresentanteNome(){
         rep1.setNome("Tiago Leite");
         Assert.assertEquals("nome errado", rep1.getNome(), "Tiago Leite");
     }
	 
	@Test
	public void RepresentanteId(){
		rep1.setId(12345);
		Assert.assertEquals("id errado", rep1.getId(), 12345);
		rep1.setId(123);
		Assert.assertEquals("id errado", rep1.getId(), 123);
		rep2.setId(1235);
		Assert.assertEquals("id errado", rep2.getId(), 1235);
	
	}
	
	@Test
	public void RepresentanteTempoLimite() throws Exception{
		//dias
		rep1.setTempoLimite(15);
		Assert.assertEquals("tempoLimite errado", rep1.getTempoLimite(), 15);
		rep1.setTempoLimite(30);
		Assert.assertEquals("tempoLimite errado", rep1.getTempoLimite(), 30);
	
	}
	
	@Test
    public void RepresentanteUltimaDataDeVisita() throws Exception{
            //ano, mes, dia
            rep1.setUltimaDataDeVisita(dataPassada);
            Assert.assertEquals("data errada", rep1.getUltimaDataDeVisita(), dataPassada);
            rep1.setUltimaDataDeVisita(dataPassada);
            Assert.assertEquals("data errada", rep1.getUltimaDataDeVisita(), dataPassada);
            
            try{
            	rep1.setUltimaDataDeVisita(dataFutura);
            }catch(Exception ex){
            	Assert.assertEquals("data errada", rep1.getUltimaDataDeVisita(), dataPassada);
                
                rep2.setUltimaDataDeVisita(hoje);
                Assert.assertEquals("data errada", rep2.getUltimaDataDeVisita(), hoje);	
            	
            }
            
            

    }
    
}
	


